/**
 * 生成随机len位数字
 */
export const randomLenNum = (len, date) => {
	let random = ''
	random = Math.ceil(Math.random() * 100000000000000).toString().substr(0, len || 4)
	if (date) random = random + Date.now()
	return random
}

/**
 * toFixed
 * @param str
 * @returns {string}
 */
export function toFixedNum(str) {
	if (str) {
		return parseFloat(str).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,'); //使用正则替换，每隔三个数加一个','
		// return parseFloat(str).toFixed(2)
	}
	return '0.00'
}


export function chooseImg(count=1,sizeType=['compressed'],sourceType=['album','camera']) {
	return new Promise((resolve, reject) => {
		uni.chooseImage({
			count: count,
			sizeType: sizeType,
			sourceType:sourceType,
			success: (res)=> {
				resolve(res)
			},
			fail:(error)=>{
				reject(error)
			}
		})
	})
}

export function chooseImg_(chooseImgtype) {
	// const sourceType = chooseImgtype ? chooseImgtype : ['album', 'camera'];
	// console.log({sourceType});
	return new Promise((resolve, reject) => {
		uni.chooseImage({
			count: 1,
			sizeType: ['compressed'],
			sourceType:chooseImgtype,
			success: (res) => {
				resolve(res)
			},
			fail: (error) => {
				reject(error)
			}
		})
	})
}


// 预览 图片
export function previewImage(list,index = 0){
	uni.previewImage({
		urls:list,
		current:index
	})
}
